I am trying to delete a string from list then write it back to a file [closed]

Posted by bradb on Programmers See other posts from Programmers or by bradb
Published on 2012-04-16T00:38:26Z Indexed on 2012/04/16 5:46 UTC
Read the original article Hit count: 253

Filed under:
def mang (grocerystock):
mangchoice=int(input("What would you like to do? \n 1):Add a new product to the list? \n 2): Remove a product from the list?  \n 3: Change the quantity of an item  \n 4): Change the price of an item  \n  5): View items and their quantity and price"))
if mangchoice == 1:
    infile=open("grocery_stock.txt", 'a')
    name=input("Please enter the new product's name would you like to add:")
    quant=int(input("Please enter the new product's quantity"))
    price=float(input("Please enter the new product's price"))
    grocerystock[0]=name
    grocerystock[1]=quant
    grocerystock[2]=price
    gS=str(grocerystock)
    gs=gS.strip("[',']")
    infile.write(gs + '\n')
if mangchoice == 2:
    namedelete=input("what item would you like to remove")
    a=open("grocery_stock.txt", 'r')
    data_list= a.readlines()
    a.close()
    print (data_list)
    del data_list[namedelete]
    b= open ("grocery_stock.txt", 'w')
    b.writelines(data_list)
    b.close()
def intro():
    choice=(int(input("Would you like to go to Managerial mode or Shop mode?(press 1 for Managerial and 2 for shop mode, to quit press 3)")))


    if choice == 1:
        print ('lets go')
        mang(grocerystock)
    elif choice == 0 :
        print ('loser')

grocerystock= ["","",""]

intro()

This is all the code i have written so far any ideas? The code that i am trying to delte is under if mangchoice == 2:

© Programmers or respective owner

Related posts about python